import React from 'react';
import Notes from './Notes';





class MyApp extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            notes:[
                {
                    'id':'21321321',
                    'title':'hello world',
                    'content':'first content'
                },
                {
                    'id':'123213213',
                    'title':'hello world 2',
                    'content':'second content'
                }
            ]
        }
    }
    addNote() {
        console.log('addNote',this);
        this.setState({
            notes:this.state.notes.concat([{
                'id':new Date(),
                'title':'form add',
                'content':'form add'
            }])
        })
    }
    editNote(id,content){
        if(content.trim()){
            return;
        }
        const notes=this.state.notes.map((note)=>{
            if(note.id==id&&content){
                note.content=content;
            }
            return note;
        })
    }
    render() {
            const notes=this.state.notes;
            console.log(Notes,this);
            return (
                <div className="container">
                 <button onClick={this.addNote.bind(this)}>+</button>
                        <Notes />
                </div>
            )
        
    }
}

export default MyApp;
